functions = []
x = 0
var compose = function (functions) {

    return function (x) {
        let res = x
        while (functions.length) {
            res = functions.pop()(res)
        }
        return res
    }
}



const fn = compose([x => x + 1, x => 2 * x])
fn(4) // 9

const fn1 = compose([x => x + 1, x => x * x, x => 2 * x])
fn1(4)